﻿<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>宇通车联网账号查询</title>
    <meta name="viewport"
          content="width=device-width,height=device-height,inital-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no">
    <link rel="stylesheet" type="text/css" href="css/reset.css">
    <meta charset="utf-8">
    <link rel="stylesheet" href="css/index.css"/>
</head>
<body>
<!-- banner图 -->
<div class="banner">
    <img src="images/logo.png" width="100%"/>
</div>
<div>
    <form onsubmit="return false;">
        <div class="inputs" ><span>VIN</span><input type="text" style="margin-left: 50px" name="" placeholder="VIN" id="et_vin">
        </div>
        <p></p>
        <div class="inputs"><span>手机号</span><input type="number" name="" placeholder="手机号码" id="et_phone"></div>
        <p></p>
        <div class="inputs yzm"><span>验证码</span><input type="number" name="" placeholder="短信验证码" id="code">
            <button id="getverify">获取验证码</button>
        </div>
        <button id="btn_check">查询</button>
    </form>
</div>
<script type="text/javascript" src="jquery-1.9.0.min.js"></script>
<script type="text/javascript">
    var countdown=60;
    function settime(val) {
        if (countdown == 0) {
            val.removeAttribute("disabled");
            val.innerText="获取验证码";
            countdown = 60;
        } else {
            val.setAttribute("disabled", true);
            val.innerText="重新发送(" + countdown + ")";
            countdown--;
            setTimeout(function() {
                settime(val)
            },1000);
        }
    }
    $("#getverify").click(function () {
        var phone=$("#et_phone").val();
        if(checkMobile()){
            settime(this);
            sendVerify(phone);
        }
    });
    $("#btn_check").click(function () {
        var phone=$("#et_phone").val();
        var code=$("#code").val();
        if(checkMobile()) {
            verifycode(phone,code);
        }
        return false;
    });
    var sendTemplate = function (openid, loginname, password, appEditionName, url) {
        $.ajax({
            url: "/api/batch/sendtemplate?openid="+openid+"&name="+loginname+"&pwd="+password+"&entername="+appEditionName+"&url="+url,
            type: 'GET',
            async: false,
            success: function (data) {
                console.log("data", data);
            },
            error: function (xhr) {
                console.log("error");
            }
        });
    };
    function toNext() {
        var vin = $("#et_vin").val();
        var phone=$("#et_phone").val();
        $.ajax({
            url: "https://eat.vehicleplus.net/voss/ent/getEntLoginInfo?token=PCDoWJMPwloLBrsoGrt&vin=" + vin+"&phone="+phone,
            type: 'GET',
            async: false,
            success: function (data) {
                console.log("data", data)
                if (parseInt(data.code) == 0) {
                    sendTemplate(getvalue("openid"),data.data.loginname,data.data.password,data.data.appEditions[0].appEditionName,data.data.appEditions[0].url);
                    var hh = "./index03.html?vin=" + vin + "&name=" + data.data.loginname + "&password=" + data.data.password + "&url=" + data.data.appEditions[0].url + "&entername=" + data.data.appEditions[0].appEditionName;
                    location.href = encodeURI(hh);
                } else {
                    if(parseInt(data.code) ==104){
                        location.href = "./index02.html?info=您提供的手机号不是购车时预留的手机号，可返回更改号码再尝试，或拨打客服电话咨询，谢谢";
                    }else{
                        location.href = "./index02.html";
                    }
                }
            },
            error: function (xhr) {
                console.log("error")
                location.href = "./index02.html";
            }
        });
    }
    function checkMobile(){
        var sMobile =$("#et_phone").val();
        if(!(/^1[34578]\d{9}$/.test(sMobile))){
            alert("手机号不正确");
//            document.mobileform.mobile.focus();
            return false;
        }else{
            return true;
        }
    }
    function sendVerify(phone) {
        $.ajax({
//            url: "http://ytxny.yutong.com/platform/thirdVerification/getVerificationCode",
            url:"/api/batch/send",
            type: 'GET',
            async: false,
            headers :{
                "Accept": "application/json;charset=UTF-8",
                "x-credential-username": "verificationCode"
            },
            data: {'phone':phone},
            success: function (data) {
                console.log("data", data)
            },
            error: function (xhr) {
                console.log("error")
//                location.href = "./index02.html";
            }
        });
    }
    function verifycode(phone,code) {
        $.ajax({
//            url: "http://ytxny.yutong.com/platform/thirdVerification/vaildVerificationCode",
            url:"/api/batch/check",
            type: 'POST',
            async: false,
            headers :{
                "Accept": "application/json;charset=UTF-8",
                "x-credential-username": "verificationCode"
            },
//            data: {checkCode:{"phone":phone,"code":code}},
            data:{"phone":phone,"code":code},
            success: function (data) {
                console.log("data", data)
                if(data.code==1){
                    toNext();
                }else{
                    alert('验证码错误');
                }
            },
            error: function (xhr) {
                console.log("error")
            }
        });
    }
    function getvalue(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var search = window.location.search;
        search=decodeURI(search);
        var r = search.substr(1).match(reg);
        if (r != null) return unescape(r[2]);
        return null;
    }
</script>
</body>

</html>